#!/usr/bin/env bash

db_name=trending_topic_beta
delta_schema=(\
    "id     varchar(32),"\
    "reads  bigint,"\
    "discussions bigint,"\
    "fans   bigint,"\
    "timestamp  varchar(10)")
initial_topics_bk_schema=(\
    "id     varchar(32),"\
    "reads  bigint,"\
    "discussions     bigint,"\
    "fans   bigint,"\
    "name   varchar(500),"\
    "timestamp varchar(10)")
initial_topics_schema=(\
    "id     varchar(32),"\
    "link   varchar(500),"\
    "reads  bigint,"\
    "discussions     bigint,"\
    "fans   bigint"\
)
topics_schema=(\
    "id         varchar(32)," \
    "name       varchar(500),"\
    "description    varchar(1000),"\
    "tags       varchar(100),"\
    "categories       varchar(100),"\
    "districts       varchar(50),"\
    "link       varchar(500),"\
    "presenter  varchar(100),"\
    "presenter_link   varchar(500)"\
)

psql $db_name <<__EOF
    drop table if exists delta;
    drop table if exists initial_topics;
    drop table if exists initial_topics_bk;
    drop table if exists topics;
    create table delta (${delta_schema[@]});
    create table initial_topics (${initial_topics_schema[@]});
    create table initial_topics_bk (${initial_topics_bk_schema[@]});
    create table topics (${topics_schema[@]});
__EOF

